package com.global.emc.spring.exception.handler;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.support.RequestContextUtils;

import com.global.emc.core.exception.IEMCException;
import com.global.emc.core.exception.handler.IEMCExceptionMessagesHandler;

/**   
 *  
 * @Description:  [处理EMCException类型异常消息]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年2月20日 下午10:57:28]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年2月20日 下午10:57:28]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
public class EMCExceptionMessagesHandlerManager {
	
	private List<IEMCExceptionMessagesHandler> emcExceptionMessagesHandler;

	public List<IEMCExceptionMessagesHandler> getEmcExceptionMessagesHandler() {
		return emcExceptionMessagesHandler;
	}

	public void setEmcExceptionMessagesHandler(
			List<IEMCExceptionMessagesHandler> emcExceptionMessagesHandler) {
		this.emcExceptionMessagesHandler = emcExceptionMessagesHandler;
	}

	public void handlerExceptionMessages(HttpServletRequest request, HttpServletResponse response, Object handlerMethod, IEMCException emcException) {
		if(null == emcExceptionMessagesHandler)
			return;
		
		resolverMessages(emcException, request);
	}
	
	protected void resolverMessages(IEMCException emcException, HttpServletRequest request) {
		for (IEMCExceptionMessagesHandler emcExceptionMessagesResolver : emcExceptionMessagesHandler) {
			if (emcExceptionMessagesResolver.supports(emcException)){
				emcExceptionMessagesResolver.resolverMessages(emcException, RequestContextUtils.getLocale(request));
				return;
			}
		}
	}

}
